5.02 内置函数
内置函数是在python解释器启动时,就已经加载到内存中的。
因此任何时候都可以直接调用这些函数
内置函数分类:
类型转换函数:int()、 float() 、str() 、list() 、set()
数学相关函数:abs()、 round()、 pow()、 divmod()
字符串处理函数:len()、split()、replace()
文件和输入输出函数:open()、 read()、 write()、 input() 、print()
对象操作函数:dir()、getattr()、setattr()、hasattr()、delattr()
序列操作函数:len()、max()、min()、sum()、append()、pop()
其他常用函数:globals()、locals()、eval()、exec()、type()、id(、isinstance()
#获取商和余数
a=15.3
b=5
t=divmod(11,3)
print(t)
#获取商除
t2=11/3
print(t2)
#四舍五入
t1=round(t2,1)
print(t1)
#幂次方
t4=pow(2,27)
print(t4)
返回值:
(3, 2)
3.66666666666666
3.7
134217728
#字符串分割
text="张三,李四,王五,赵六"
result=text.split(",")
print(result) #字符串拆分后是一个列表
#字符串替换
result2=text.replace(",",";")
print(result2)
返回值:
['张三', '李四', '王五', '赵六']
张三;李四;王五;赵六